#ifndef CRREGS_H
#define CRREGS_H

#include "type.h"

struct avm_cr0_t {
	bit32u val32;

#define IMPLEMENT_ACCESSOR(NAME, NUM) \
	avm_bool get_##NAME() { \
		return 1 & (val32 >> NUM); \
	} \
	void set_##NAME(bit8u bit) { \
		val32 = (val32 & ~(1 << NUM)) | (bit ? (1 << NUM) : 0); \
		return; \
	} \

	IMPLEMENT_ACCESSOR(PE, 0);
	IMPLEMENT_ACCESSOR(MP, 1);
	IMPLEMENT_ACCESSOR(EM, 2);
	IMPLEMENT_ACCESSOR(TS, 3);
	IMPLEMENT_ACCESSOR(ET, 4);
	IMPLEMENT_ACCESSOR(NE, 5);
	IMPLEMENT_ACCESSOR(WP, 16);
	IMPLEMENT_ACCESSOR(AM, 18);
	IMPLEMENT_ACCESSOR(NW, 29);
	IMPLEMENT_ACCESSOR(CD, 30);
	IMPLEMENT_ACCESSOR(PG, 31);

	bit32u get_CR0() {
		return val32;
	}
	void set_CR0(bit32u val) {
		// ET is hardcoded to 1
		val32 = val | 0x10;
	}

};

#endif
